package com.jsnj33.pdaproject.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jsnj33.pdaproject.R;
import com.jsnj33.pdaproject.bean.ToollookBean;

import java.util.List;

public class ToollookAdapter extends RecyclerView.Adapter<ToollookAdapter.ViewHodler> {
    Context context;
    List<ToollookBean.DataBean> list;


    public ToollookAdapter(Context context, List<ToollookBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.tooklookadapter, parent, false);
        return new ViewHodler(view);
    }

    @Override
    public void onBindViewHolder(ViewHodler holder, int position) {
        holder.tvNotice.setText(list.get(position).getTZ_NO() + "");
        holder.tvTime.setText(list.get(position).getZC_DD() + "");
        holder.tvTranslateName.setText(list.get(position).getZC_NAME() + "");
        holder.tvTranslateNum.setText(list.get(position).getQTY_FIN() + "");
        holder.tvNohegeNum.setText(list.get(position).getQTY_LOST() + "");
        holder.tvNohegeReason.setText(list.get(position).getREM() + "");
        holder.tvOrderNum.setText(list.get(position).getQTY() + "");
        holder.tvProductName.setText(list.get(position).getPRD_NAME() + "");
        holder.tvProductNumber.setText(list.get(position).getPRD_NO() + "");
        holder.tvTuzhiNumber.setText(list.get(position).getTZH() + "");
        holder.tvJiaoqiNumber.setText(list.get(position).getEND_DD() + "");
        holder.tvBumen.setText(list.get(position).getDEP_NAME() + "");
        holder.tvOperator.setText(list.get(position).getUSR_NAME() + "");
        holder.tvProperty.setText(list.get(position).getSAL_NAME() + "");
        holder.tvJihua.setText(list.get(position).getJH_NO() + "");
        holder.tvDevice.setText(list.get(position).getSEB_NO() + "");
        switch (list.get(position).getMXP() + "") {
            case "1":
                holder.tvMXP.setText("是");
                break;
            default:
                holder.tvMXP.setText("否");
                break;
        }
    }

    @Override
    public int getItemCount() {
        if (list == null) {
            return 0;
        } else {
            return list.size();
        }
    }

    class ViewHodler extends RecyclerView.ViewHolder {
        TextView tvNotice;//通知单号
        TextView tvTime;//报工时间
        TextView tvTranslateName;//工序名称
        TextView tvTranslateNum;//报工数量
        TextView tvNohegeNum;//不合格数量
        TextView tvDevice;//设备号
        TextView tvNohegeReason;//不合格原因
        TextView tvOrderNum;//订单数量
        TextView tvProductName;//品         名
        TextView tvProductNumber;//品         号
        TextView tvTuzhiNumber;//图  纸  号
        TextView tvJiaoqiNumber;//交        期
        TextView tvBumen;//部        门
        TextView tvOperator;//操  作  员
        TextView tvProperty;//物  业  员
        TextView tvJihua;//计划单号
        TextView tvMXP;//是否卖芯片

        public ViewHodler(View itemView) {
            super(itemView);
            tvNotice = itemView.findViewById(R.id.tvNotice);
            tvTime = itemView.findViewById(R.id.tvTime);
            tvTranslateName = itemView.findViewById(R.id.tvTranslateName);
            tvTranslateNum = itemView.findViewById(R.id.tvTranslateNum);
            tvNohegeNum = itemView.findViewById(R.id.tvNohegeNum);
            tvDevice = itemView.findViewById(R.id.tvDevice);
            tvNohegeReason = itemView.findViewById(R.id.tvNohegeReason);
            tvOrderNum = itemView.findViewById(R.id.tvOrderNum);
            tvProductName = itemView.findViewById(R.id.tvProductName);
            tvProductNumber = itemView.findViewById(R.id.tvProductNumber);
            tvTuzhiNumber = itemView.findViewById(R.id.tvTuzhiNumber);
            tvJiaoqiNumber = itemView.findViewById(R.id.tvJiaoqiNumber);
            tvBumen = itemView.findViewById(R.id.tvBumen);
            tvOperator = itemView.findViewById(R.id.tvOperator);
            tvProperty = itemView.findViewById(R.id.tvProperty);
            tvJihua = itemView.findViewById(R.id.tvJihua);
            tvMXP = itemView.findViewById(R.id.tvMXP);
        }
    }

    /**
     * 更新数据
     *
     * @param list
     */
    public void updata(List<ToollookBean.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    /**
     * 清空数据
     */
    public void clear() {
        if (list != null) {
            list.clear();
        }
        notifyDataSetChanged();
    }
}
